<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:lzc="http://schemas.icitadel.com/Lazarus/Compiled.xsd" version="1.0">

  <xsl:output method="text"/>

  <xsl:include href="../../common.xsl" />
  <xsl:include href="../../convert.xsl" />

  <xsl:template match="lzc:project">
    <xsl:apply-templates select="lzc:datasource" />
  </xsl:template>

  <xsl:template match="lzc:datasource">#!/bin/bash

echo '<xsl:value-of select="ancestor::lzc:project/@name" />'
echo '-------------------------------------------------------------------------'
echo 'create_schema.sh'
echo 'Creates the Google Cloud SQL Database on the specified instance.'
echo ' '
echo ' '
echo 'Syntax: crebas.sh <xsl:value-of select="@location + ' ' + @schema" />'
echo ' '

DEFAULT_MACHINE='<xsl:value-of select="@location" />'
DEFAULT_SCHEMA='<xsl:value-of select="@schema" />'

CheckMachine ()
{
  echo ' '
  echo 'Checking for specified Machine Name.'
  if [ $1 ]; then
    machine_name=$1
  else
    machine_name=DEFAULT_MACHINE
  fi
}

CheckSchema ()
{
  echo ' '
  echo 'Checking for specified Schema.'
  if [ $2 ]; then
    schema_name=$2
  else
    schema_name=DEFAULT_SCHEMA
  fi
}

CheckMachine
CheckSchema
_GOOGLE_SQL='/usr/bin/google_sql/google_sql.sh '$machine_name' '$schema_name

echo ' '
echo 'Running Scripts...'
echo ' '

pushd Procedures

echo '*** Step 1: Dropping Stored Procedures.'
_GOOGLE_SQL &lt; drop_procs.sql
echo ' '

popd

echo '*** Step 2: Dropping Indexes.'
_GOOGLE_SQL &lt; IndexDrop.sql
echo ' '

echo '*** Step 3: Dropping References.'
_GOOGLE_SQL &lt; ReferenceDrop.sql
echo ' '

echo '*** Step 4: Dropping Tables.'
_GOOGLE_SQL &lt; IndexCreate.sql

echo ' '
echo 'Database Teardown Complete'
</xsl:template>
</xsl:stylesheet>
